UE.registerUI('fileupload',function(editor,uiName){
    
    //创建dialog
    var dialog = new UE.ui.Dialog({
        //指定弹出层中页面的路径，这里只能支持页面,因为跟addCustomizeDialog.js相同目录，所以无需加路径
        iframeUrl: window.__CTX__.cloudIframe,
        
        //需要指定当前的编辑器实例
        editor:editor,
        //指定dialog的名字
        name: uiName,
        //dialog的标题
        title:"上传图片",
        
        //指定dialog的外围样式
        cssRules:"width: 530px;height:330px;",

        //如果给出了buttons就代表dialog有确定和取消
        buttons:[
            {
                className:'edui-okbutton',
                label:'确定',
                onclick:function () {
                  
                  
                  var $dialog = $($(this)[0].target).parents('#edui_fixedlayer');
                  
                  // Step2 get iframe from dialog
                  var $dialogIframe = $('iframe', $dialog);
                  
                  // Step3 get uploaded status
                  var uploaded = $dialogIframe.contents().find("#input_uploaded").val();
                  
                  if(uploaded) {
                    
                    // Step4 get uploadedData
                    var uploadedData = {};
                    uploadedData.hash = $dialogIframe.contents().find("#input_hash").val();
                    uploadedData.key = $dialogIframe.contents().find("#input_key").val();
                    uploadedData.tempDomain = $dialogIframe.contents().find("#input_temp_domain").val();
                    uploadedData.prodDomain = $dialogIframe.contents().find("#input_prod_domain").val();
                    console.log(uploadedData);
                    
                    // insert image into ueditor
                    editor.execCommand('inserthtml', '<img src="' + uploadedData.prodDomain + '/' + uploadedData.key + '-600 " id="'+ uploadedData.hash +'" style="max-width: 100%;">');
                    
                    // Step5 get tempImages from localStorage
                    var tempImages = JSON.parse(localStorage.getItem('tempImages'));
                    if(tempImages == null || tempImages.length == 0) {
                      tempImages = [];
                    }
                    
                    tempImages.push(uploadedData);  // push will add data at the end
                    
                    // Step7 remove uploaded data in localStorage
                    localStorage.removeItem('uploadedData');
                    
                    dialog.close(true);
                  }
                }
            },
            {
                className:'edui-cancelbutton',
                label:'取消',
                onclick:function () {
                    dialog.close(false);
                }
            }
        ]});

    //参考addCustomizeButton.js
    var btn = new UE.ui.Button({
        name:'上传图片' ,
        title:'上传图片' ,
        //需要添加的额外样式，指定icon图标，这里默认使用一个重复的icon
        cssRules :'background-position: -726px -77px;',
        onclick:function () {
            //渲染dialog
            dialog.render();
            dialog.open();
        }
    });

    return btn;
}/*index 指定添加到工具栏上的那个位置，默认时追加到最后,editorId 指定这个UI是那个编辑器实例上的，默认是页面上所有的编辑器都会添加这个按钮*/);